/**
 * 路由系统
 */
define("route",[],function(){
    return {
        run:function(configs){
            if(typeof(configs) != 'object'){
                return false;
            }

            var route_require = [];
            for( config in configs){
                if(this.matching(config)){
                    route_require.push(configs[config]);
                }
            }

            if(route_require.length>0)require(route_require);
        },
        matching:function(arg){
            var pathname = window.location.pathname;
            if(arg == '/' && (pathname == "/" || pathname=='/index.html' || pathname=='/index.php' ) ){ //首页匹配
                return true;
            }else if(arg == '*'){ //全局匹配
                return true;
            }else if(arg.indexOf("*") != -1){
                var reg = new RegExp(arg,"g");
                return reg.test(pathname);
            }else if(arg == pathname){
                return true;
            }
            return false;
        }
    };
});

/**
 * 配置和运行应用程序
 */
(function(config){
    var require_config = config.require_config;
    var paths = {
        "jquery":["common/jquery/jquery-1.11.3/jquery"],
    };
    var ex_paths =require_config.paths;
    for(path in ex_paths){
        paths[path] = ex_paths[path];
    }

    require.config({
        baseUrl:require_config.baseUrl,
        paths:paths
    });

    require(['route'],function(route){
        route.run(config.route_config);
    });



})($_Config());